#ifndef _PLUSOLVER_H
#define _PLUSOLVER_H

#ifdef DEBUG
#define private public
#define protected public
#endif

#include "common.h"
#include <iostream>
#include <memory.h>

using namespace std;

template <typename T> 
class PLUSolver {
private:
    int swap(int row1, int row2); // row exchange for A and P
    int reverseLU();
    int triReserve(T** L);
    int transpose(T** M);
    int gemm(T** M1, T** M2, T** res, int n);
    T* Y;
    T** rL;
    T** rU;
    T** L;
    T** U;
    
public:
    T** A;
    T** rA;
    T* b;
    T* X;
    int n;
    int* P;
    PLUSolver();
    ~PLUSolver(); // 对象析构时，对Y的内存进行回收。考虑到用户会复用A、P，保留该数据
    PLUSolver(T** A, int n, T* b, int* P);
    
    int PLU();
    int Solve(T* _X);
    int GetReverseA(T** _rA);
    int PrintMatrix(T** M, int size, std::string name);
    int PrintVector(T* Vec, int size, std::string name);
};


#endif